package co.fitstart.api.dao;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.demo2do.core.persistence.GenericDaoSupport;
import co.fitstart.entity.coach.CoachSigninRecord;
import co.fitstart.entity.coach.CoachSigninStatistic;
import co.fitstart.entity.course.schedule.CourseSchedule;
import co.fitstart.entity.principal.Principal;

/**
 * 
 * @author haiyan_xiao
 *
 */
@Repository("coachDaoSupport")
public class CoachDaoSupport {
    @Autowired
    private GenericDaoSupport genericDaoSupport;
    
    /**
     * 
     * @param coach
     * @param month
     * @return
     */
    public CoachSigninStatistic getCoachSigninStatistic(Principal coach, String month) {
        String sentence = "FROM CoachSigninStatistic WHERE principal = :coach AND month = :month";
        
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("coach", coach);
        parameters.put("month", month);
        
        return genericDaoSupport.searchForObject(sentence, parameters, CoachSigninStatistic.class);
    }
    
    /**
     * load coachSigninRecord by courseSchedule
     * @param courseSchedule
     * @return
     */
    public CoachSigninRecord loadCoachSigninRecord(CourseSchedule courseSchedule) {
        String sentence = "FROM CoachSigninRecord WHERE principal = :coach AND courseDay = :courseDay"
                + " AND courseTime = :courseTime AND ignored = true";
        
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("coach", courseSchedule.getCoach());
        parameters.put("courseDay", courseSchedule.getOccurDate());
        parameters.put("courseTime", courseSchedule.getOccurHour());
        
        return genericDaoSupport.searchForObject(sentence, parameters, CoachSigninRecord.class);
    }
}
